﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace Pcb.Common
{
    public class _JavaScript
    {
        /// <summary>
        /// 弹出 JavaScript 对话框
        /// </summary>
        public static void Alert(Page page, string message)
        {
            string JavaScript = "<script type='text/javascript' language='javascript'>";
            JavaScript += "alert('" + message + "')";
            JavaScript += "</script>";

            page.Response.Write(JavaScript);                          
        }

        /// <summary>
        /// c#实现escape编码
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string Escape(string s)
        {
            StringBuilder sb = new StringBuilder();
            byte[] ba = System.Text.Encoding.Unicode.GetBytes(s);
            for (int i = 0; i < ba.Length; i += 2)
            {
                sb.Append("%u");
                sb.Append(ba[i + 1].ToString("X2"));

                sb.Append(ba[i].ToString("X2"));
            }
            return sb.ToString();
        } 

    }
}
